﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Qimo

{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            var cmds = "select * from Articles";
            var jin = DbHelper.GetDataTable(cmds);
            dataGridView1.DataSource = jin;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.AllowUserToAddRows = false;

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

    
        private void button1_Click(object sender, EventArgs e)
        {
            var Title = textBox1.Text;
            var sqlCon = string.Format("select * from Articles  where  Title like '%{0}%'", Title);
            var ress = DbHelper.GetDataTable(sqlCon);
            dataGridView1.DataSource = ress;
        }

       
        private void button2_Click(object sender, EventArgs e)
        {
            Form3 form3 = new Form3();
            var reo = form3.ShowDialog();
            if (reo == DialogResult.Yes)
            {
                var Title = textBox1.Text;
                var cmd = string.Format("select * from Articles where Title like '%{0}%'", Title);
                var dt = DbHelper.GetDataTable(cmd);
                dataGridView1.DataSource = dt;
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
		
	}
        private void button3_Click_1(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                var sd = dataGridView1.SelectedRows[0];
                var id = (int)sd.Cells["Id"].Value;
                var qus = MessageBox.Show("请确定删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (qus.Equals(DialogResult.Yes))
                {
                    var sqlCon = string.Format("delete from Articles where id = {0}", id);
                    var con = DbHelper.Addddd(sqlCon);
                    if (con > 0)
                    {
                        var Title = textBox1.Text;
                        var cmd = string.Format("select * from Articles where Title like '%{0}%'", Title);
                        var dt = DbHelper.GetDataTable(cmd);
                        dataGridView1.DataSource = dt;

                        MessageBox.Show("删除成功！");
                    }
                }
            }
        }
      
    }
}
